![]() |
PATH![]() |
![]() ![]() |
The Range reference form specifies a series of objects of the same class in the same container. You can specify the objects with a pair of indexes (such as words 12 thru 24 ) or with a pair of boundary objects (such as words from paragraph 3 to paragraph 5 ).
every className from boundaryReference1 to boundaryReference2
pluralClassName from boundaryReference1 to boundaryReference2
className startIndex ( thru | through ) stopIndex
pluralclassName startIndex ( thru | through ) stopIndex
className is a singular class ID (such as word or paragraph ).
pluralclassName is the plural class identifier defined by AppleScript or an application (such as words or paragraphs ).
boundaryReference1 and boundaryReference2 are references to objects that bound the range. The range includes the boundary objects. You can use the reserved word beginning in place of boundaryReference1 to indicate the position before the first object of the container. Similarly, you can use the reserved word end in place of boundaryReference2 to indicate the position after the last object in the container.
startIndex and stopIndex are the indexes of the first and last object of the range (such as 1 and 10 in words 1 thru 10 ).
The value of a Range reference is a list of the objects in the range. If the specified container does not contain all of the objects specified in the range, an error is returned. For example, the following reference results in an error.
words 1 thru 3 of {1, 2, 3}
--results in an error
In the following example, the phrase folders 3 thru 4 is a range reference that specifies a list of two folders in the container startup disk.
tell application "Finder"
folders 3 thru 4 of startup disk
end tell
--typical result: (depends on contents of startup disk)
--{folder "AppleScript" of startup disk of application "Finder", ¬
--folder "Apple Extras" of startup disk of application "Finder"}
In the following example, files is a reference that is a synonym for every file , and the phrase folders 3 thru 4 of startup disk is a container reference made up of the range reference folders 3 thru 4 and the container startup disk.
tell application "Finder"
files of folders 3 thru 4 of startup disk
end tell
To get the result, AppleScript first gets the value of the container, which is a list of two folders on the startup disk. It then gets every file in each of the folders, which results in a single list of file names. The actual files in the list depend on the contents of the startup disk.
If you specify a Range reference as the container for a property or object, as in
name of files 2 thru 3 of startup disk
the result is a list containing the specified property or object for each object of the container. The number of items in the list is the same as the number of objects in the container. For example, the value of the reference in this example might be
{"ASP memory report, 3/3/99", "BBEdit 5.0.2 Update.img"}
The first item in the list is the name of the second file on the startup disk, and the second item is the name of the third file.
To refer to a contiguous series of characters--instead of a list--when specifying a range of text objects, use the text element. Text is an element of most text objects and is also an element of AppleScript strings.
For example, compare the values of the following references.
words 1 thru 4 of "We're all in this together"
--result: {"We're", "all", "in", "this"}
text from word 1 to word 4 of "We're all in this together"
--result: "We're all in this"
text of words 1 thru 4 of "We're all in this together"
--result: {"We're", "all", "in", "this"}